﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Windows;
using BrainTechLLC.WPF;
using WpfImageDuplicates;

namespace SettingsWindowHandler.Plugin
{
    public class SettingsWindowHandler : WindowHandlerBase<SettingsWindow, Window>, ISettingsWindowHandler
    {
        public SettingsWindowHandler(Window1 parentWindow)
            : base(parentWindow)
        {
            _parentWindow = parentWindow;
        }

        public override void OpenWindow(Window owner)
        {
            if (_window == null)
            {
                _window = new SettingsWindow() { Owner = owner };
                _window.SettingsViewModel = (_parentWindow as Window1).SettingsWatcher.SettingsViewModel;
                _window.Closed += new EventHandler(_window_Closed);
            }

            _window.Show();
            _window.Focus();
        }

        private void _window_WantCalcBlurs(object sender, EventArgs e)
        {
            Window1.MainWindow.CollectionView.BlurHandler.CalculateBlurs();
        }

        private void _window_WantSaveSettings(object sender, EventArgs e)
        {
            (_parentWindow as Window1).SettingsWatcher.SettingsViewModel.SaveSettings(FilePaths._settingsPath);
        }

        private void _window_Closed(object sender, EventArgs e)
        {
            _window.Closed -= _window_Closed;
            // herehere 
            _window.SettingsViewModel = null;
            _window = null;
        }
    }
}
